
<p><h1>Add Packages</h1></p>
<form id="packagesForm" name="packagesForm" method="post"  action="" enctype="multipart/form-data">
<table>
	<tr>
		<td>Package Name</td><td>:</td><td><input type="text" name="packageName" id="packageName" <?if(isset($this->package->package_name)&& $this->package->package_name!=''){?>value="<?echo $this->package->package_name;?>"<?}else{?>value=''<?}?>/><span id="errorpackageName" style="color:red"></span></td>
	</tr>
	<tr>
		<td>Package Price</td><td>:</td><td><input type="text" name="packagePrice" id="packagePrice" <?if(isset($this->package->price)&& $this->package->price!=''){?>value="<?echo $this->package->price;?>"<?}else{?>value=''<?}?>/><span id="errorpackagePrice" style="color:red"></span></td>
	</tr>
	<tr>
		<td>Number of days</td><td>:</td><td><input type="text" name="packageDays" id="packageDays" value="365"/></td>
	</tr>
	<tr>
		<td>package Image</td><td>:</td><td>
		<?if(isset($this->package->package_image)&& $this->package->package_image!=''){?>
			<!--<img src="<?php echo $this->basePath() ?>/images/1-Subject/Combo/<?echo $this->package->package_image;?>">-->
			<img src="<?php echo $this->basePath() ?>/images/1-Subject/dev-combo-subj/<?echo $this->package->package_image;?>">			
		<?}?>
		<input type="hidden" id="hidfile" name="hidfile" value="<?if(isset($this->package->package_image)&& $this->package->package_image!=''){echo $this->package->package_image;}?>">
		<input type="file" name="packageImage" id="packageImage" /></td>
	</tr>
	<tr>
		<td>Is Free</td><td>:</td>
		<td>
			<select id="isFree" name="isFree">
				<option value="">Select</option>
				<?if(isset($this->package->is_free)&& $this->package->is_free!=''){
				if($this->package->is_free=='1'){?>
				<option value="1" selected="selected">Yes</option>
				<?}else{?>
				<option value="1">Yes</option>
				<?}if($this->package->is_free=='0'){?>
				<option value="0" selected="selected">No</option>
				<?}else{?>
				<option value="0">No</option>
				<?}}else{?>
				<option value="1">Yes</option>
				<option value="0">No</option>
				<?}?>
			</select><span id="errorisFree" style="color:red"></span>
		</td>
	</tr>
	<tr>
		<td>Board</td><td>:</td>
		<td>
			<select id="packageBoard" name="packageBoard" onchange="getPackageClasses()">
				<option value="">Select</option>
				<?if(count($this->boards)!=0){foreach($this->boards as $boards){?>
				<?if(isset($this->package->board)&& $this->package->board!=''){?>
				<?if($this->package->board==$boards->name){?>
				<option value="<?echo $boards->rack_id .'-/'.$boards->name;?>" selected="selected"><?echo $boards->name;?></option>
				<?}else{?>
				<option value="<?echo $boards->rack_id .'-/'.$boards->name;?>"><?echo $boards->name;?></option>
				<?}}else{?>
				<option value="<?echo $boards->rack_id .'-/'.$boards->name;?>"><?echo $boards->name;?></option>
				<?}}}?>
			</select><span id="errorpackageBoard" style="color:red"></span>
		</td>
	</tr>
	<tr>
		<td>class</td><td>:</td>
		<td>
		<select id="packageClass" name="packageClass" onchange="getPackageSubjects()">
			<option value="">Select</option>
			<?if(isset($this->package->class)&& $this->package->class!=''){?>
			<option  value="<?echo $this->package->board_class_id .'-/'.$this->package->class;?>" selected="selected"><?echo $this->package->class;?></option>
			<?}?>
		</select><span id="errorpackageClass" style="color:red"></span>
		</td>
	</tr>
	<tr>
		<td>Subjects</td><td>:</td>
		<td>
		<select id="packageSubjects" name="packageSubjects" multiple="multiple" >
			<option value="">Select</option>
			<? $subidss='';$subids='';if(count($this->subjectNames)!=0){
				foreach($this->subjectNames as $key=>$subjectNames){
			?>
			<option  value="<?echo $key;?>" selected="selected"><?echo $subjectNames;?></option>
			<?$subidss.=$key.','; $subids=trim($subidss,',');}}?>
		</select><span id="errorpackageSubjects" style="color:red"></span>
		</td>
	</tr>
</table>
<input type="hidden" id="hidpackageId" name="hidpackageId" <?if(isset($this->package->package_id)&& $this->package->package_id!=''){?>value="<?echo $this->package->package_id;?>"<?}else{?>value=''<?}?> />
<input type="hidden" id="subjectIds" name="subjectIds" value='' />

<p><a href="javascript:void(0);" onclick="packageSubmit()">SAVE</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="<?php echo $this->Url('zfcadmin');?>/packages-list">BACK</a></p>
</form>

<script>
function packageSubmit(){
	
	var ids=$('#packageSubjects').val();
	$('#subjectIds').val(ids);
	
	var flag=true;
	
	if($('#packageName').val()==""){
		$('#errorpackageName').html('Package Name Required');
		flag=false;
	}else{
		$('#errorpackageName').html('');
	}
	
	if($('#packagePrice').val()==""){
		$('#errorpackagePrice').html('Price Required');
		flag=false;
	}else{
		$('#errorpackagePrice').html('');
	}
	
	if($('#isFree').val()==""){
		$('#errorisFree').html('Is Free Required');
		flag=false;
	}else{
		$('#errorisFree').html('');
	}
	
	if($('#packageBoard').val()==""){
		$('#errorpackageBoard').html('Board Required');
		flag=false;
	}else{
		$('#errorpackageBoard').html('');
	}
	
	if($('#packageClass').val()==""){
		$('#errorpackageClass').html('Class Required');
		flag=false;
	}else{
		$('#errorpackageClass').html('');
	}
	
	if($('#gender').val()==""){
		$('#errorgender').html('Gender Required');
		flag=false;
	}else{
		$('#errorgender').html('');
	}
	
	if($('#packageSubjects').val()==null){ 
		$('#errorpackageSubjects').html('Subjects Required');
		flag=false;
	}else{
		$('#errorpackageSubjects').html('');
	}

	if(flag==false){
		return false;
	}else{
		$('#packagesForm').submit();
	}
}
function getPackageClasses(){
	board_id = $('#packageBoard').val().split('-/');
	$.ajax({
		type:'POST',
		url:   ADMIN_BASE_URL+'/package/changeclasses',
		data:{classid:board_id[0],type:'register'},
		success: function(data){ 
		$("#packageClass").html(data);
		}
	});
}
function getPackageSubjects(){
	class_id = $('#packageClass').val().split('-/');
	$.ajax({
		type:'POST',
		url:   ADMIN_BASE_URL+'/admin/add-packages',
		data:{class_id:class_id[0]},
		success: function(data){ 
		$("#packageSubjects").html(data);
		}
	});
}

</script>
